package com.bw.mybatistest.controller;

import com.bw.mybatistest.bean.Employee;
import com.bw.mybatistest.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @ResponseBody
    @RequestMapping("/getEmp")
    public Employee getEmployeeById(@RequestParam("id") Integer id){
        //获取Employee对象
        Employee employeeById = employeeService.getById(id);
        return employeeById;
    }
    @ResponseBody
    @RequestMapping("/addEmp")
    public String getEmployeeById(@RequestParam("name") String name){
        //获取Employee对象
        Employee employee = new Employee();
        employee.setLastName(name);
        employee.setId(1000);
        employeeService.save(employee);
        return "ok";
    }
}